package com.bysj.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.github.kevinsawicki.http.HttpRequest;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class WeChatServiceImp implements WeChatService {
    @Override
    public JSONObject codetoopenid(String code) {
        Map<String, String> data = new HashMap<String, String>();
        data.put("appid", "wx36cf7236c116ca5a");
        data.put("secret", "b9555e0ae774b21e0e84d2134215be1f");
        data.put("js_code", code);
        data.put("grant_type", "authorization_code");
        String response = HttpRequest.get("https://api.weixin.qq.com/sns/jscode2session").form(data).body();
        JSONObject obj= JSON.parseObject(response);//将json字符串转换为json对
        return obj;
    }
}
